// https://leetcode.cn/problems/minimum-distance-between-bst-nodes/
// Created by ade on 2022/8/16.
//

class Solution {
public:
    int before = -10000000;
    int distance = INT_MAX;
    int minDiffInBST(TreeNode* root) {
        dfs(root);
        return distance;
    }

    void dfs(TreeNode * root){
        if(!root) return;
        dfs(root->left);
        distance = min(abs(root->val - before), distance);
        before = root->val;
        dfs(root->right);
    }
};